package com.x.xiaoshuo.manager;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

import com.x.xiaoshuo.R;
import com.x.xiaoshuo.ui.download.DownloadActivity;


public class DownloadNotificationManager {
    private static final int NOTIFY_ID = 0;
    private NotificationManager mNotificationManager;
    private Notification mNotification;
    Context context;

    public DownloadNotificationManager(Context context) {
        this.context = context;
        init();
    }

    void init() {
        mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        int icon = R.mipmap.ic_launcher;
        CharSequence tickerText = "开始下载";
        long when = System.currentTimeMillis();
        mNotification = new Notification(icon, tickerText, when);

        mNotification.flags = Notification.FLAG_ONGOING_EVENT;

        RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.download_notify);

        mNotification.contentView = contentView;

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, DownloadActivity.class), 0);
        // 指定内容意图
        mNotification.contentIntent = contentIntent;

        mNotificationManager.notify(NOTIFY_ID, mNotification);

    }

    public void updateMessage(String title, String propess) {
        RemoteViews contentView = mNotification.contentView;
        contentView.setTextViewText(R.id.title, title);
        contentView.setTextViewText(R.id.propress, propess);
        mNotificationManager.notify(NOTIFY_ID, mNotification);
    }


}
